var common = function () {
    return {
        Initial: function (getLanguages) {
            if (typeof (getLanguages) == "undefined" || !getLanguages) {
                //没有输入，不需要设置Language ，返回默认的的东西
                var language = localStorage.getItem("language");  //获取名称为“key”的值
                if (!language) {
                    localStorage.setItem("language", "zh");  // 初始化存入zh
                    language = "zh";
                }
                return language;
            } else {
                //有输入
                localStorage.setItem("language", getLanguages);
                return getLanguages;
            }
        }, dateFormatDataDay: function (row, column) {
            //表格上面格式化日期
            var datec = row[column.property];
            var now = new Date(datec);
            if (datec == null) {
                now = new Date();
            }
            var year = now.getFullYear();  //取得4位数的年份
            var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
            var day = now.getDate();      //返回日期月份中的天数（1到31）
            return year + "-" + month + "-" + day
        },
        dateFormatTime: function (row, column) {
            var dateTemp = row[column.property];
            var date = new Date(dateTemp);
            var YY = date.getFullYear() + '-';
            var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
            var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
            var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
            var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
            return YY + MM + DD + " " + hh + mm + ss;
        },
        timestampToTime: function (timestamp) {
            var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
            var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
            var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
            var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
            strDate = Y + M + D + h + m + s;
            return strDate;
        },
        getTime: function (data, type) {
            var _data = data;
            //如果是13位正常，如果是10位则需要转化为毫秒
            if (String(data).length == 13) {
                _data = data
            } else {
                _data = data * 1000
            }
            const time = new Date(_data);
            const Y = time.getFullYear();
            const Mon = time.getMonth() + 1;
            const Day = time.getDate();
            const H = time.getHours();
            const Min = time.getMinutes();
            const S = time.getSeconds();
            //自定义选择想要返回的类型
            if (type == "Y") {
                return `${Y}-${Mon}-${Day}`
            } else if (type == "H") {
                return `${H}:${Min}:${S}`
            } else {
                return `${Y}-${Mon}-${Day} ${H}:${Min}:${S}`
            }
        }, dateToString(date) {
            // 将data转化为String
            var year = date.getFullYear();
            var month = (date.getMonth() + 1).toString();
            var day = (date.getDate()).toString();
            if (month.length == 1) {
                month = "0" + month;
            }
            if (day.length == 1) {
                day = "0" + day;
            }
            var dateTime = year + "-" + month + "-" + day;
            return dateTime;
        },
        // 小写转大写
        toUppercase: function (o, parName) {
            if (o && o[parName]) {
                o[parName] = o[parName].toUpperCase();
            }
        }
    }
}();

if (typeof(Vue) == "function") Vue.prototype.common = common;